import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:shared_preferences/shared_preferences.dart';

bool turn_on = true;
bool mic_on = false;

int rgbIndex = 0;
String ledNum = '200'; // 存储输入的值

String rgbIndexKey = 'rgbIndexKey';
String ledNumKey = 'ledNumKey';

///主题背景颜色
const Color Color_theme = Color(0xFF56B6F6);
const Color Color_select_btn = Color(0xFF56B6F6);

///键盘色效果
const Color Color_left = Color(0xFF6BCFFB);
const Color Color_right = Color(0xFF2D6EEC);

///子视图背景颜色
const Color Color_bg_view = Color(0xFF2F2F32);
const Color Color_line_view = Color(0xFF4C4C4E);

const Color Color_btn_hight = Color(0xFFFF0206);
const LinearGradient localGradient = LinearGradient(
  begin: Alignment.topLeft, // 渐变的开始位置，左边
  end: Alignment.bottomRight, // 渐变的结束位置，右边
  colors: [
    Color_left, // 起始颜色
    Color_right, // 结束颜色
  ],
);

// 保存字符串
Future<void> saveString(String key, String value) async {
  final prefs = await SharedPreferences.getInstance();
  await prefs.setString(key, value);
}

// 获取字符串
Future<String?> getString(String key) async {
  final prefs = await SharedPreferences.getInstance();
  return prefs.getString(key);
}

class GlobalConfig {
  static double scaleH = 0.0;
}

class assets {
  static const String _basePath = 'assets/images/';

  static String getImagePath(String imageName) {
    return '$_basePath$imageName.png';
  }

  // 定义具体的图片资源
  static const String add = '${_basePath}add.png';
  // static const String arror_left = '${_basePath}arror_left.png';
  // static const String arror_right = '${_basePath}arror_right.png';
  static const String arror_left = '${_basePath}-.png';
  static const String arror_right = '${_basePath}+.png';
  static const String back = '${_basePath}back.png';
  static const String bg_view = '${_basePath}bg_view.png';
  static const String Color_btn = '${_basePath}Color_btn.png';
  static const String color_point = '${_basePath}color_point.png';
  static const String color = '${_basePath}color.png';
  static const String connect_high = '${_basePath}connect_high.png';
  static const String connect = '${_basePath}connect.png';
  static const String Custom_btn = '${_basePath}Custom_btn.png';
  static const String disconnect_hight = '${_basePath}disconnect_hight.png';
  static const String disconnect = '${_basePath}disconnect.png';
  static const String light_on = '${_basePath}light_on.png';
  static const String light_off = '${_basePath}light_off.png';
  static const String mic_off = '${_basePath}mic_off.png';
  static const String mic_on = '${_basePath}mic_on.png';
  static const String Mode_btn = '${_basePath}Mode_btn.png';
  static const String more = '${_basePath}more.png';
  static const String delete = '${_basePath}delete.png';
  static const String scroll = '${_basePath}scroll.png';
  static const String setting = '${_basePath}setting.png';
  static const String trun_off = '${_basePath}trun_off.png';
  static const String trun_on = '${_basePath}trun_on.png';
  static const String slider_p = '${_basePath}slider_p.png';
  static const String Voice_control_btn = '${_basePath}Voice_control_btn.png';
  static const String refresh = '${_basePath}refresh.png';

  ///读取本地文件
  static Future<Uint8List?> readBinFile(String fileName) async {
    try {
      // 读取 bin 文件
      ByteData data = await rootBundle.load('assets/$fileName');

      // 将 ByteData 转换为 Uint8List 并返回
      return data.buffer.asUint8List();
    } catch (e) {
      print('Error reading bin file: $e');
      return null;
    }
  }
}

const List<String> modeList = [
  'Auto Cycle',
  'Forward Colorful',
  'Backward Colorful',
  'Forward seven-color',
  'Backward seven-color',
  'Forward RD/GN/BU',
  'Backward RD/GN/BU',
  'Forward YE/CN/VT',
  'Backward YE/CN/VT',
  'Forward 6 colors RD',
  'Backward 6 colors RD',
  'Forward 6 colors GN',
  'Backward 6 colors GN',
  'Forward 6 colors BU',
  'Backward 6 colors BU',
  'Forward 6 colors CN',
  'Backward 6 colors CN',
  'Forward 6 colors YE',
  'Backward 6 colors YE',
  'Forward 6 colors VT',
  'Backward 6 colors VT',
  'Forward 6 colors WH',
  'Backward 6 colors WH',
  'Forward trailing Colorful',
  'Backward trailing Colorful',
  'Forward trailing RD',
  'Backward trailing RD',
  'Forward trailing GN',
  'Backward trailing GN',
  'Forward trailing BU',
  'Backward trailing BU',
  'Forward trailing YE',
  'Backward trailing YE',
  'Forward trailing CN',
  'Backward trailing CN',
  'Forward trailing VT',
  'Backward trailing VT',
  'Forward trailing WH',
  'Backward trailing WH',
  'Forward stream 7 colors',
  'Backward stream 7 colors',
  'Forward stream RD&GN&BU',
  'Backward stream RD&GN&BU',
  'Forward stream YE&CN&VT',
  'Backward stream YE&CN&VT',
  'Forward stream RD&GN',
  'Backward stream RD&GN',
  'Forward stream GN&BU',
  'Backward stream GN&BU',
  'Forward stream YE&BU',
  'Backward stream YE&BU',
  'Forward stream YE&CN',
  'Backward stream YE&CN',
  'Forward stream CN&VT',
  'Backward stream CN&VT',
  'Forward stream BK&WH',
  'Backward stream BK&WH',
  'Open curtain 7colours',
  'Close curtain 7colours',
  'Open curtain RD&GN&BU',
  'Close curtain RD&GN&BU',
  'Open curtain YE&CN&VT',
  'Close curtain YE&CN&VT',
  'Forward follow colourful',
  'Backward follow colourful',
  'Forward follow RD&GN&BU',
  'Backward follow RD&GN&BU',
  'Forward follow YE&CN&VT',
  'Backward follow YE&CN&VT',
  'Forward float 7 colours',
  'Backward float 7 colours',
  'Forward float RD&GN&BU',
  'Backward float RD&GN&BU',
  'Forward float YE&CN&VT',
  'Backward float YE&CN&VT',
  'HOP 7 colors',
  'Hop red green blue',
  'Hop red green blue',
  'Strobe 7 colors',
  'Strobe RD&GN&BU',
  'Strobe YE&CN&VT',
  'Gradual 7 colors',
  'Gradual red yellow',
  'Gradual red purple',
  'Gradual green cyan',
  'Gradual GN&YE',
  'Gradual BU&VT',
  'Close curtain red',
  'Close curtain green',
  'Close curtain blue',
  'Close curtain ye',
  'Close curtain cyan',
  'Close curtain purple',
  'Close curtain white',
  'Open curtain red',
  'Open curtain blue',
  'Open curtain yellow',
  'Open curtain cyan',
  'Open curtain purple',
  'Open curtain white',
  'Horse race red',
  'Horse race green',
  'Horse race blue',
  'Horse race yellow',
  'Horse race cyan',
  'Horse race purple',
  'Horse race white',
  'Forward run red',
  'Backward run red',
  'Forward run green',
  'Backward run green',
  'Backward run blue',
  'Forward run yellow',
  'Backward run yellow',
  'Forward run cyan',
  'Backward run cyan',
  'Forward run purple',
  'Backward Run VT',
  'Forward run white',
  'Backward run white',
  'Forward run 7 colors',
  'Backward run 7 colors',
  'Forward run RD&GN&BU',
  'Backward run RD&GN&BU',
  'Forward run YE&CN&VT',
  'Backward run YE&CN&VT',
  'Forward run BU&YE&VT',
  'Forward run GN&BU&YE',
  'Backward run BU&YE&VT',
  'Forward run RD ON WH',
  'Backward run RD ON WH',
  'Forward run GN ON RD',
  'Backward run GN ON RD',
  'Forward run BU ON GN',
  'Backward run BU ON GN',
  'Forward run YE ON BU',
  'Backward run YE ON BU',
  'Forward run CN ON YE',
  'Backward run CN ON YE',
  'Forward run VT ON CN',
  'Backward run VT ON CN',
  'Forward run WH ON VT',
  'Backward run WH ON VT',
  'Forward run WH ON RD',
  'Backward run WH ON RD',
  'Forward run 7 color ON RD',
  'Backward run 7 color ON RD',
  'Forward run 7 color ON GN',
  'Backward run 7 color ON GN',
  'Forward run 7 color ON BU',
  'Backward 4un 7 color ON BU',
  'Forward 4un 7 color ON YE',
  'Backward run 7 color ON YE',
  'Forward run 7 color ON CN',
  'Backward run 7 color ON CN',
  'Forward run 7 color ON VT',
  'Backward run 7 color ON VT',
  'Forward run 7 color ON WH',
  'Backward run 7 color ON WH',
  'Forward flow WH&RD&WH',
  'Backward flow WH&RD&WH',
  'Forward flow WH&GN&WH',
  'Backward flow WH&GN&WH',
  'Forward flow WH&BU&WH',
  'Backward flow WH&BU&WH',
  'Forward flow WH&YE&WH',
  'Backward flow WH&YE&WH',
  'Forward flow WH&GN&WH',
  'Backward flow WH&GN&WH',
  'Forward flow WH&VT&WH',
  'Backward flow WH&VT&WH',
  'Forward flow RD&WH&RD',
  'Backward flow RD&WH&RD',
  'Forward flow GN&WH&GN',
  'Backward flow GN&WH&GN',
  'Forward flow BU&WH&BU',
  'Backward flow BU&WH&BU',
  'Forward flow YE&WH&YE',
  'Backward flow YE&WH&YE',
  'Forward flow CN&WH&CN',
  'Backward flow CN&WH&CN',
  'Forward flow VT&WH&VT',
  'Backward flow VT&WH&VT',
  'Forward run GN ON BU',
  'Backward run GN ON BU',
  'Forward run GN ON RD',
  'Backward run GN ON RD',
  'Forward run RD ON BU',
  'Backward run RD ON BU',
  'Forward run CN ON YE',
  'Backward run CN ON YE',
  'Forward run YE ON VT',
  'Backward run YE ON VT',
  'Forward run WH ON YE',
  'Backward run WH ON YE',
  'Forward run YE ON WH',
  'Backward run YE ON WH',
  'Forward swab 7 colors',
  'Backward swab 7 colors',
  'Forward swab RD&GN&BU',
  'Backward swab RD&GN&BU',
  'Forward swab YE&CN&VT',
  'Backward swab YE&CN&VT',
  'Open curtain swab 7colours',
  'Close curtain swab 7colours',
  'Open curtain swab RGB',
  'Close curtain swab RGB',
  'Open curtain swab YCP',
  'Close curtain swab YCP'
];
